@echo off & setlocal enabledelayedexpansion

echo "start build proto"
call ..\..\..\..\3rdparty\artifactory\protoc.sh

set compiler=..\..\..\..\3rdparty\artifactory\protoc\protoc.exe
@REM call D:\Jenkins\workspace\simone_windows_test\cybertron\3rdparty\artifactory\protoc.sh

@REM set compiler=D:\Jenkins\workspace\simone_windows_test\cybertron\3rdparty\artifactory\protoc\protoc.exe
set extension=*.proto

set src_dir=%cd%
set output_dir=Output

set option_cpp=cpp
set option_js=js
set option_python=python
set option_csharp=csharp

if not exist %output_dir% mkdir %output_dir%

echo Generate %option_cpp% header and source files
call :compile %option_cpp%,%output_dir%\%option_cpp%,%src_dir%

echo Generate %option_js% source files
call :compile %option_js% %output_dir%\%option_js% %src_dir%

echo Generate %option_python% source files
call :compile %option_python% %output_dir%\%option_python% %src_dir%

echo Generate %option_csharp% source files
call :compile %option_csharp% %output_dir%\%option_csharp% %src_dir%

exit /b %errorlevel%

rem function acce pt option, input output
:compile
set option=%~1
set output=%~2
set src=%~3

rd %output% /s /q
mkdir %output%

rem travel src dir, compile each file with extension .proto
for /f %%i in ('dir /b/s %extension%') do (
	set path=%%i
	%compiler% --%option%_out=%output% "!path:%cd%\=!"
)

exit /b 0

